package com.poorstu.web;

import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.common.base.model.PaginationSupport;
import com.common.base.web.BaseAction;
import com.poorstu.manager.PartTimeManager;
import com.poorstu.model.PartTimeMod;

public class PartTimeMagAction extends BaseAction {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		try{
			PartTimeManager partTime=(PartTimeManager)getBean("partTimeManager");
			
			List<PartTimeMod> partTimeList=partTime.selectPartTimeALL();
			
			request.setAttribute("partTimeList", partTimeList);
			
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			for(int i=0;i<partTimeList.size();i++)
			{
				partTimeList.get(i).setStart(sdf.format(partTimeList.get(i).getStartTime()));
				
			}
			
			int pageNum = Integer.parseInt(request.getParameter("pageNum"));
			PaginationSupport ps = partTime.searchAllPartTimeByPage(pageNum);
			request.setAttribute("rolelist", ps.getItems());
			request.setAttribute("proPage", ps.getPreviousIndex());
			request.setAttribute("nextPage", ps.getNextIndex());
			request.setAttribute("firstPage", ps.getFirstIndex());
			request.setAttribute("lastPage", ps.getLastIndex());
				
			//sdf.format(partTimeList.);
			//request.setAttribute(name, o);
			
		 return mapping.findForward("succ");
			
		 }catch(Exception e){
			e.printStackTrace();
			return	mapping.findForward("failure");
		}
	}
}
